
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>未来元素</title>
</head>
<body>
    <div id="app">
        <h2>houdunren.com</h2>
    </div>
    <script>
        function show(){
            console.log(this.textContent);
        }
        //使用事件代理对未来元素进行事件绑定
        const app = document.querySelector('#app');
        const h2 = document.querySelectorAll('h2');
        app.addEventListener('click',() => {
            show.call(event.target);
        });
        let newH2 = document.createElement('h2');
        newH2.textContent = 'hdcms.com';
        app.append(newH2);
    </script>
</body>
</html>
